package de.bazinga.rotw.base.attacker;

import com.captiveimagination.jgn.message.Message;
import com.captiveimagination.jgn.message.type.CertifiedMessage;
import com.captiveimagination.jgn.message.type.PlayerMessage;
import com.captiveimagination.jgn.message.type.TimestampedMessage;
import com.jme.math.Vector3f;

import de.bazinga.rotw.game.RotwGameState;
import de.bazinga.rotw.network.message.GameMessage;

public class AttackerCreateMessage extends Message implements CertifiedMessage, PlayerMessage, TimestampedMessage, GameMessage {
	private int attackerId = 0;
	private Vector3f location = null;
	
	public void handleMessage(RotwGameState game, Message msg, boolean server) {
		if(!(msg instanceof AttackerCreateMessage)) return ;

		// Player touched a item
		if(!server && location != null) {
			BaseAttacker att = AttackerList.getUnusedAttacker();
			
			att.setAttackerId(attackerId);
			
			att.updateRenderState();
			att.reset(location);
			game.getRootNode().attachChild(att);
			att.updateRenderState();
			att.updateGeometricState(0, false);
			
			AttackerList.addAttacker(att);
		}
	}

	public void setAttackerId(int attackerId) {
		this.attackerId = attackerId;
	}

	public int getAttackerId() {
		return attackerId;
	}

	public void setLocation(Vector3f location) {
		this.location = location;
	}

	public Vector3f getLocation() {
		return location;
	}
}